package com.tbdp.lsmp.common;

import com.tbdp.lsmp.util.ResourceUtil;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author xbkaishui
 * @version $Id: Configuration.java, v 0.1 2017-11-05 下午2:02 xbkaishui Exp $$
 */
public class Configuration {

    private static final Configuration instance = new Configuration();

    private static final String CONFING_NAME = "config_lsmp.properties";

    private Properties properties;

    private Configuration() {
        loadResource();
    }

    //TODO load config_lsmp.properties
    private void loadResource() {
        try {
            InputStream inputStream = null;
            inputStream = ResourceUtil.getInputStream(CONFING_NAME);
            if (inputStream == null) {
                inputStream = ResourceUtil.getInputStream("src/resources/" + CONFING_NAME);
            }
            properties = new Properties();
            properties.load(inputStream);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public static Configuration getInstance() {
        return instance;
    }

    public String getProperty(String key, String def) {
        return properties.getProperty(key, def);
    }

    public Object get(String key) {
        return properties.get(key);
    }

    public String getProperty(String key) {
        return properties.getProperty(key);
    }
}
